package y_2025.m05.d23;

import java.util.Scanner;

public class StoneMerge {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] stones = new int[n];
        for (int i = 0; i < n; i++) {
            stones[i] = scanner.nextInt();
        }
        scanner.close();

        // 处理环形问题：将数组复制一份接在后面
        int[] doubledStones = new int[2 * n];
        for (int i = 0; i < n; i++) {
            doubledStones[i] = stones[i];
            doubledStones[i + n] = stones[i];
        }

        // 前缀和数组
        int[] prefixSum = new int[2 * n + 1];
        for (int i = 1; i <= 2 * n; i++) {
            prefixSum[i] = prefixSum[i - 1] + doubledStones[i - 1];
        }

        // DP数组初始化
        int[][] dpMin = new int[2 * n][2 * n];
        int[][] dpMax = new int[2 * n][2 * n];
        for (int i = 0; i < 2 * n; i++) {
            for (int j = 0; j < 2 * n; j++) {
                if (i == j) {
                    dpMin[i][j] = 0;
                    dpMax[i][j] = 0;
                } else {
                    dpMin[i][j] = Integer.MAX_VALUE;
                    dpMax[i][j] = 0;
                }
            }
        }

        // 区间DP
        for (int len = 2; len <= n; len++) {
            for (int i = 0; i + len - 1 < 2 * n; i++) {
                int j = i + len - 1;
                for (int k = i; k < j; k++) {
                    int sum = prefixSum[j + 1] - prefixSum[i];
                    dpMin[i][j] = Math.min(dpMin[i][j], dpMin[i][k] + dpMin[k + 1][j] + sum);
                    dpMax[i][j] = Math.max(dpMax[i][j], dpMax[i][k] + dpMax[k + 1][j] + sum);
                }
            }
        }

        // 处理环形结果
        int minScore = Integer.MAX_VALUE;
        int maxScore = 0;
        for (int i = 0; i < n; i++) {
            minScore = Math.min(minScore, dpMin[i][i + n - 1]);
            maxScore = Math.max(maxScore, dpMax[i][i + n - 1]);
        }

        System.out.println(minScore);
        System.out.println(maxScore);
    }
}